package com.share.design.mediator.demo01;

import java.util.HashMap;
import java.util.Map;

/**
 * 中介者实现类
 * @author caifan
 * @since 2022/11/13
 */
public class ChatRoomImpl implements ChatRoom {

    private Map<String, User> userMap = new HashMap<>();

    @Override
    public void sendMessage(String msg, String userId) {
        User user = userMap.get(userId);
        user.receive(msg);
    }

    @Override
    public void addUser(User user) {
        this.userMap.put(user.getId(), user);
    }
}
